package com.hfstu.framework.core.orm.hibernate;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.hfstu.framework.core.orm.IGenericDAO;
import com.hfstu.framework.model.BaseModel;
import com.hfstu.framework.util.StringUtil;

/**
 * 增，删，改，查，查询所有五种操作的基类
 * 
 * 
 * @param <T>
 * @param <ID>
 */
@SuppressWarnings("all")
public class BaseGenericDAOImpl<T extends BaseModel, PK extends Serializable>
		extends MyHibernateDaoSupport<T, PK> implements IGenericDAO<T, PK> {

	private Class<T> persistentClass;

	@SuppressWarnings("unchecked")
	public BaseGenericDAOImpl() {
		this.persistentClass = (Class<T>) ((ParameterizedType) getClass()
				.getGenericSuperclass()).getActualTypeArguments()[0];
	}

	public Class<T> getPersistentClass() {
		return persistentClass;
	}

	protected String getEntityName() {
		return persistentClass.getName();
	}

	public void delete(PK id) {
		super.deleteEntity(id);
	}

	public T getById(PK id) {
		return super.getEntityById(id);
	}

	public T save(T entity) {
		return super.saveEntity(entity);
	}

	public T saveOrUpdate(T entity) {
		return super.saveOrUpdateEntity(entity);
	}

	public T update(T entity) {
		return super.updateEntity(entity);
	}

	public void delete(T entity) {
		super.deleteEntity(entity);
	}

	public List<T> findAll() {
		return super.getAllEntities();
	}

	public List<T> findAllByHql(String hql, Object... values) {
		return super.findListByQuery(hql, values);
	}

	public <X> List<X> findAllBySql(String sql, Object... values) {
		return super.findListBySQLQuery(sql, values);
	}

	public List<T> getByIds(PK[] ids) {
		return super.get(Arrays.asList(ids));
	}

}
